<template>
	<el-dialog title="延期申请对话框" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<div style="text-align: center;font-size: 18px;font-weight: 600;margin-bottom: 15px;">
				{{title}}
			</div>
			<el-form-item label="延期事由" prop="content">
				<el-input v-model="form.content" placeholder="延期事由" clearable maxlength="480" type="textarea"></el-input>
			</el-form-item>
			<el-form-item label="延期日期" prop="delayTime">
				<el-date-picker :disabled-date="publishDateAfter" v-model="form.delayTime" placeholder="开始时间" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
			</el-form-item>
			<el-form-item label="备注" prop="remark">
				<el-input v-model="form.remark" maxlength="380" clearable type="textarea"></el-input>
			</el-form-item>
			<el-form-item label="相关附件" prop="attachId">
				<sc-upload-file :apiObj="apiObj"  v-model="fileList" :data="{module:'supervision'}" :showFileList="false" @success="addNewFile">
					<el-button type="primary" icon="el-icon-upload">上传附件</el-button>
				</sc-upload-file>
				<attach-menu v-model:attachIds="form.attachId" :roleFlag="4" :preview="true"></attach-menu>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
import AttachMenu from "@/views/module/attachMenu";

export default {
	components: {
		AttachMenu
	},
	emits: ['success', 'closed'],
	data() {
		return {
			visible: false,
			isSaveing: false,
			apiObj:this.$API.file.attach.uploadFile,
			fileList:[],
			title:"",
			//表单数据
			form: {
				delayId:'',
				processId:"",
				content:"",
				delayTime:"",
				attachId: "",
				remark: ""
			},
			//验证规则
			rules: {
				content: [
					{required: true, message: '延期事由不能为空'}
				],
				delayTime:[
					{required: true, message: '延期日期不能为空'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		publishDateAfter(time){
			return time.getTime()<(Date.now()-24*60*60*1000)
		},
		//显示
		open(){
			this.visible = true;
			return this
		},
		//表单提交方法
		submit(){
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.supervision.supervisionDelay.insertSupervisionDelay.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		addNewFile(res, file)
		{
			let tArr =[];
			if(this.form.attachId!=undefined&&this.form.attachId!=null&&this.form.attachId!=''){
				tArr = this.form.attachId.split(",");
			}
			tArr.push(res.data.attachId);
			this.form.attachId = tArr.join(",");
		},
		setData(data){
			this.form.delayId = data.delayId
			this.form.processId = data.processId
			this.title = data.title
		},
	}
}
</script>

<style>
</style>
